import SendSms from './sms/components/SendSms';
import RadioDialog from './sms/components/RadioDialog';
import VotingResultDialog from './voting/public/votingDialog/index';
import { Provider } from 'mobx-react';
import { WeaLocaleProvider } from 'ecCom';
import store from '../meeting/stores';

const req = require.context('./', true, /^\.\/\w+\/index\.js$/);

const Routes = [];
let stores = {};
req.keys().forEach((path) => {
  const mod = req(path);
  Routes.push(mod.Route);
  stores = { ...stores, ...mod.stores };
});
const { getLocaleLabelByCode } = WeaLocaleProvider;

class RadioDialogProvider extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
    };
  }
  componentDidMount() {
    // 多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('radio').then(() => this.setState({ reRender: true }));
  }
  render() {
    return <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@tr8rue`} {...stores}><RadioDialog ecId={`${this && this.props && this.props.ecId || ''}_RadioDialog@toq6yf`} {...this.props} /></Provider>;
  }
}

class SendSmsProvider extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
    };
  }
  componentDidMount() {
    // 多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('sms').then(() => this.setState({ reRender: true }));
  }
  render() {
    const { isCustom = true } = this.props;
    if (isCustom) return <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@6n8t5b`} {...stores}><SendSms ecId={`${this && this.props && this.props.ecId || ''}_SendSms@3gdade`} {...this.props} /></Provider>;
    return <SendSms ecId={`${this && this.props && this.props.ecId || ''}_SendSms@b489x6`} {...this.props} />;
  }
}
class VotingResultProvider extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
    };
  }
  componentDidMount() {
    // 多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('voting').then(() => this.setState({ reRender: true }));
  }

  render() {
    return <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@dns0w0`} {...stores}><VotingResultDialog ecId={`${this && this.props && this.props.ecId || ''}_VotingResultDialog@mb88fu`} {...this.props} /></Provider>;
  }
}

module.exports = {
  Route: Routes,
  store: stores,
  com: { SendSms: SendSmsProvider, VotingResult: VotingResultProvider, RadioDialog: RadioDialogProvider },
};
